<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a>结算</a>
        <a><cite>审核记录</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">审核记录</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show" style="margin-bottom:1%;">
                    <div class="layui-row">
                        <div class="layui-form" style="float:right;">
                            <div class="layui-form-item" style="margin:0;">
                                <div class="layui-input-inline">
                                    <input type="text" name="createTimeStart" id="createTimeStart" autocomplete="off"
                                           placeholder="开始时间" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="createTimeEnd" id="createTimeEnd" autocomplete="off"
                                           placeholder="结束时间" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="infoId" id="infoId" placeholder="结算商ID" autocomplete="off"
                                           class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="accountName" id="accountName" placeholder="账户名"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="settOrderId" id="settOrderId" placeholder="结算单号"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <select name="settStatus" id="settStatus" lay-search="">
                                        <option value="-99">状态</option>
                                        <option value="1">等待审核</option>
                                    </select>
                                </div>
                                <button id="search" class="layui-btn" data-type="reload">搜索</button>
                            </div>
                        </div>
                    </div>
                </div>
                <table id="auditList" lay-filter="auditList"></table>
            </div>
        </div>
    </div>
</div>
<script>
    //标题内容模板
    var tplTitle = function (d) {
        var bankNetName = "开户网点：";
        if(d.province){
            bankNetName += d.province;
        }
        if(d.city){
            bankNetName += d.city;
        }
        bankNetName += d.bankNetName;
        var text = "开户银行：" + d.bankName + "  " + bankNetName + "  账户名：" + d.accountName + "  账号：" + d.accountNo + "  结算金额(元)：" + d.settAmount/100;
        return '<a class="layui-btn layui-btn-primary layui-btn-xs copyBtn" data-clipboard-text="' + text + '" >复制</a>' +
            '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-href="sett/detail/id=' + d.id + '">查看</a> ' +
            '<a class="layui-btn layui-btn-xs" lay-href="sett/audit/auditD/id=' + d.id + '">审核</a>'
    };

    var tplStatus = function(d){
        if(d.settStatus == 1) {
            return "<span style='color: red'>等待审核</span>";
        }else if(d.settStatus == 2) {
            return "<span style='color: darkgreen'>已审核</span>";
        }else if(d.settStatus == 3) {
            return "<span style='color: indigo'>审核不通过</span>";
        }else if(d.settStatus == 4) {
            return "<span style='color: blueviolet'>打款中</span>";
        }else if(d.settStatus == 5) {
            return "<span style='color: blue'>打款成功</span>";
        }else if(d.settStatus == 6) {
            return "<span style='color: black'>打款失败</span>";
        }
    };

    layui.use(['table', 'util', 'element', 'form', 'layer', 'laydate'], function () {
        var table = layui.table
            , $ = layui.$
            , form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
            , element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        table.render({
            elem: '#auditList'
            , url: layui.setter.baseUrl + '/sett/audit_list'
            , where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            , id: 'tableReload'
            , cols: [[
                {field: 'settOrderId', width: 220, title: '结算单号', sort: true}
                , {
                    field: 'infoType',
                    title: '结算商类型',
                    templet: '<div>{{d.infoType == 1?"代理商":d.infoType == 2?"商户":""}}</div>'
                }
                , {field: 'infoId', title: '结算商ID'}
                ,{field:'infoName', title: '结算商名字' }
                /*,{field: 'settType',title: '结算类型',templet: '<div>{{d.settType == 1?"手工结算":d.settType == 2?"自动结算":""}}</div>'}*/
                , {field: 'accountName', title: '账户名'}
                , {field: 'settAmount', title: '结算金额', templet: '<div>{{d.settAmount/100}}</div>'}
                , {field: 'settFee', title: '手续费', templet: '<div>{{d.settFee/100}}</div>'}
                , {field: 'remitAmount', title: '打款金额', templet: '<div>{{d.remitAmount/100}}</div>'}
                , {field: 'settStatus', title: '结算状态', templet: tplStatus}
                , {
                    field: 'settDate',
                    title: '结算日期',
                    templet: '<div>{{ layui.util.toDateString(d.settDate, "yyyy-MM-dd") }}</div>'
                }
                , {field: 'edite', title: '操作', width: 160, templet: tplTitle}
            ]]
            , page: true
            , skin: 'line'
        });

        // 搜索
        var $ = layui.$, active = {
            reload: function () {
                var createTimeStart = $('#createTimeStart').val();
                var createTimeEnd = $('#createTimeEnd').val();
                var settOrderId = $('#settOrderId').val();
                var infoId = $("#infoId").val();
                var accountName = $('#accountName').val().trim();
                var settStatus = $("#settStatus").val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        settOrderId: settOrderId,
                        infoId: infoId,
                        accountName: accountName,
                        createTimeStart: createTimeStart,
                        createTimeEnd: createTimeEnd,
                        settStatus: settStatus
                    }
                });
            }
        };

        if(!window.clipboard || window.clipboard == undefined){
            window.clipboard = new ClipboardJS('.copyBtn');
            clipboard.on('success', function (e) {
                layer.msg("结算信息复制成功,请发送给商户确认后审核.")
                e.clearSelection();
            });
        }

        $('#search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        laydate.render({
            elem: '#createTimeStart'
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm:ss'
        });

        laydate.render({
            elem: '#createTimeEnd'
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm:ss'
        });

        // 渲染表单
        form.render();
    })
</script>